var pageii = null;
var grid = null;
$(function() {
	
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id",
		}, {
			colkey : "title",
			name : "文章标题",
			isSort:true,
		}, {
			colkey : "atype",
			name : "文章类型"
		},{
			colkey : "author",
			name : "作者"
		}, {
			colkey : "createTime",
			name : "创建时间",
			renderData : function(rowindex,data, rowdata, column) {
				if(data){
					return new Date(data).format("yyyy-MM-dd");
				}else{
					return "";
				}
			}
		}],
		jsonUrl : rootPath + '/article/selectList.shtml',
		checkbox : true,
		//serNumber : true,
		checkValue : "id"
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addArticle").click("click", function() {
		addArticle();
	});
	$("#editArticle").click("click", function() {
		editArticle();
	});
	$("#delArticle").click("click", function() {
		delArticle();
	});
});
function editArticle() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	loadPage(rootPath + '/article/addOrEdit?id=' + cbox);
}
function addArticle() {
	loadPage(rootPath+"/article/addOrEdit");

//	pageii = layer.open({
//		title : "新增",
//		type : 2,
//		area : [ "800px", "80%" ],
//		content : rootPath + '/advert/addOrEdit'
//	});
}
function delArticle() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/article/deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}